<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page isELIgnored="false" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>归还登记</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/toastr.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/tips.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/mFrame/newtool.js"></script>
    <style>

    </style>
</head>
<body>
<div class="container shadow-sm p-3 mb-5 bg-white rounded">
    <div class="row">
        <div class="col-12">
            <div id="reform" >
                <nav class="navbar  navbar-light rounded" style="background-color: #1e5379;margin-bottom: 30px;">
                    <a class="navbar-brand" href="#" style="color: white;">归还登记</a>
                </nav>

            </div>
        </div>

    </div>
    <div class="row">
        <div class="col-3"></div>
        <div class="col-6">
            <form id="form">

                <fieldset></fieldset>
                <div class="form-group row">
                    <label for="eName" class="">设备名称：</label>
                    <div class="col-lg-10">
                        <input type="text" name="eName" class="form-control" id="eName">
                    </div>
                </div>
                <div class="form-group row">
                    <label for="etype" class="row-lg-2 col-form-label">设备型号：</label>
                    <div class="col-lg-10">
                        <input type="text" name="model" class="form-control" id="model">
                    </div>
                </div>
                <div class="form-group row">
                    <label for="etype" class="row-lg-2 col-form-label">设备类型：</label>
                    <div class="col-lg-10">
                        <select class="form-control form-control-lg" name="etype" id="etype">
                            <c:forEach var="cols" items="${typeList}">
                                <option value="${cols.id}">${cols.type}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="form-group row">
                    <label for="name" class="row-lg-2 col-form-label" >归还人：&nbsp;&nbsp;&nbsp;&nbsp;</label>
                    <div class="col-lg-10">
                        <input type="text" class="form-control" name="name" id="name">
                    </div>
                </div>
                <div class="form-group row">
                    <label for="endTime" class="row-lg-2 col-form-label">归还时间：</label>
                    <div class="col-lg-10">
                        <input type="date" class="form-control" value="<%=new SimpleDateFormat("yyyy-MM-dd").format(new Date())%>" name="endTime" id="endTime">
                    </div>
                </div>
                <div class="form-group row">
                    <label for="dep" class="row-lg-2 col-form-label">归还部门：</label>
                    <div class="col-lg-10">
                        <select class="form-control form-control-lg" name="dep" id="dep">
                            <c:forEach var="cols" items="${dep}">
                                <option value="${cols.id}">${cols.lendDepar}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="form-group row">
                    <button type="button" onclick="sendData()" class="btn btn-success" id="addReData">归还设备</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <button type="button" class="btn btn-primary" id="reset">重置</button>
                </div>
            </form>
        </div>
        <div class="col-3"></div>
    </div>

</div>

</body>
<script type="text/javascript">
        var notNull = new RegExp(".*[^\s]","i");//非空认证
        $(function () {
            //加载下拉框
            /*$('.dropdown-toggle').dropdown();*/

            customTips();


            $("#eName").blur(function (){
                var ename= $("#eName").val();
                if (!notNull.test(ename)){
                    StartCheck($(".form-group")[0],"eName","不可为空","sfc",false);
                }else  if (false){
                    StartCheck($(".form-group")[0],"eName","给设备不存在","sfc",false);
                }else {
                    StartCheck($(".form-group")[0],"eName","成功","sfc",true);
                }
            });


            $("#model").blur(function (){
                var model= $("#model").val();
                if (!notNull.test(model)){
                    StartCheck($(".form-group")[1],"model","不可为空","fsca",false);
                }else  if (false){
                    StartCheck($(".form-group")[1],"model","该设备没有这个型号","fsca",false);
                }else {
                    StartCheck($(".form-group")[1],"model","成功","fsca",true);
                }
            });



            $("#name").blur(function (){
                var name= $("#name").val();
                if (!notNull.test(name)){
                    StartCheck($(".form-group").eq(3),"name","不可为空","sfax",false);
                }else  if (false){
                    StartCheck($(".form-group").eq(3),"name","该设备没有这个型号","sfax",false);
                }else {
                    StartCheck($(".form-group").eq(3),"name","成功","sfax",true);
                }
            });

        })



        function sendData() {
            var ename=   $("#eName").val();
            var etype=  $("#etype").val();
            var name=  $("#name").val();
            var model=  $("#model").val();
            var endTime= $("#endTime").val();
            var dep= $("#dep").val();
            var msg={"ename":ename,"etype":etype,
                "name":name,"model":model,"endTime":endTime,"dep":dep};
            if (ename!=null&&ename!=""&&etype!=null&&etype!=""&&
                name!=null&&name!=""&&model!=null&&model!=""&&
                endTime!=null&&endTime!=""&&dep!=null&&dep!=""
            ){
                $.ajax({
                    type:"get",
                    dataType:"json",
                    contenType:"application/json;charset=utf-8",
                    url:"${pageContext.request.contextPath}/lr/addRetEp",
                    data:{"param":JSON.stringify(msg)},
                    success:function (data) {
                        if (data.state){
                            toastr.success("操作成功");
                            reset();
                        }else {
                            toastr.error("该用户没有借出过这台设备");
                        }
                    },
                    error:function (e) {
                        console.log(e);
                        toastr.error("服务器异常");
                    }

                });


            }else{


                toastr.warning("请填入对应的数据");
            }

        }


        function reset() {
            window.parent.frames.detailed('/pj/addRet');
        }


</script>


</html>